//
//  ViewController.m
//  Homework2
//
//  Created by 王佩 on 15/9/25.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //  获取documents文件夹
    NSString * documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
    //  拼接文件夹路径
    NSString * path = [documentsPath stringByAppendingPathComponent:@"path"];
    //  创建文件管理器
    NSFileManager * fileManager = [NSFileManager defaultManager];
    //  根据路径创建文件夹
    [fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
    //  拼接文件路径
    NSString * srcPath = [path stringByAppendingPathComponent:@"test.txt"];
    //  将image转换为NSData
    UIImage * image = [UIImage imageNamed:@"1.png"];
    NSData * data = UIImagePNGRepresentation(image);
    //  根据路径将data写入文件
    [fileManager createFileAtPath:srcPath contents:data attributes:nil];
    NSLog(@"++++%@",srcPath);
    //  获取tmp目录
    NSString * tmpPath = NSTemporaryDirectory();
    NSString * toPath = [tmpPath stringByAppendingPathComponent:@"testDirectory/test.txt"];
    
    [fileManager createDirectoryAtPath:[toPath stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:nil];
   
    NSError * error = nil;
        BOOL isSuccess = [fileManager moveItemAtPath:srcPath toPath:toPath error:&error];
        NSLog(@"%d,%@",isSuccess,error);

    


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
